package com.xinmiao.test8.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.Toast;

import com.xinmiao.test8.R;

import java.util.List;

/**
 * Created by ${王俊强} on 2017/11/21.
 */

public class MyAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;
    private LayoutInflater mLayoutInflater;
    private List<DataBean> mDataBeans;

    public MyAdapter(Context context, LayoutInflater layoutInflater, List<DataBean> dataBeans) {
        mContext = context;
        mLayoutInflater = layoutInflater;
        mDataBeans = dataBeans;
    }

    @Override
    public int getItemViewType(int position) {
        return mDataBeans.get(position).getType();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (viewType == DataBean.TYPEONE) {
            return new ViewHolderOne(
                    mLayoutInflater.inflate(R.layout.itme_one, parent, false));
        } else {
            return new ViewHolderOne(
                    mLayoutInflater.inflate(R.layout.itme_two, parent, false));
        }
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof MyViewHolder) {
            ((MyViewHolder) holder).setData();
        } else {
            Toast.makeText(mContext, "bindView出错", Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public int getItemCount() {
        return mDataBeans.size();
    }
}
